﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using YWTSSys.BLL;
using YWTSSys.Library;
using YWTSSys.Model;

namespace YWTSSys.Web.MachineSys.YWTSWeb.dy
{
    public partial class AddConsumerRecord : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.新增 };
            }
        }
        protected override string DWZRef
        {
            get { return "CustomerConsumeMaster"; }
        }
        protected int CustomerId
        {
            get
            {
                return GetRequestValue<int>("CustomerId", 0);

            }
        }
        private CustomerInfo _objC = null;
        protected CustomerInfo objC
        {
            get
            {
                if (_objC == null)
                {
                    _objC = CustomerController.GetById(CustomerId);
                }
                return _objC;

            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (CustomerId == 0)
            {
                Response.Write("请先选择一个客户");
                Response.End();
            }
            if (GetRequestValue<string>("ajaxmethod", "") == "add")
            {
                addmenu();
            }
        }
        private void addmenu()
        {
            ConsumeRecordInfo obj = Request.SerializableObject<ConsumeRecordInfo>();
            obj.客户ID = CustomerId;
            obj.消费时间 = DateTime.Now;
            obj.UserId = base.User.UserId;
            obj.RealName = base.User.RealName;

            AddLog(Permission.新增, obj);

           // obj.UserName = GetRequestValue<string>("dwz.orgLookup.UserName", "");

            int r = ConsumeRecordController.Add(obj);

            if (r > 0)
                SuccessJson("添加成功");
            else
            {
                ErrorJson("添加失败");
            }
        }
    }
}